<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>实现原生Ajax请求</title>
  </head>
  <body>
    <!-- http://127.0.0.1:4523/mock/849144/user/56 -->
    <button class="btn">点击发送请求</button>
    <script>
      let btn = document.querySelector(".btn");
      btn.addEventListener("click", () => {
        const xhr = new XMLHttpRequest();
        xhr.open("GET", "http://127.0.0.1:4523/mock/849144/user/56");
        xhr.send();
        xhr.onreadystatechange = function () {
          if (xhr.readyState == 4 && xhr.status == 200) {
            console.log(xhr.responseText);
          }
        };
      });

	  async function asy1() {
		console.log(1);
		await asy2();
		console.log(2);
	  }
	  const asy2=async ()=>{
		
		await setTimeout(() => {
			Promise.resolve().then(()=>{
				console.log(3);
			});
			console.log(4);
		}, 0);
		console.log(8)
	  }
	  const asy3=async ()=>{
		Promise.resolve().then(()=>{
			console.log(6);
		})
	  }
	  asy1()
	  console.log(7);
	  asy3()

    </script>
  </body>
</html>
